package activitys;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.boboqi.test.R;

/**
 * Created by pc on 2017/2/17.
 */
public class ChildViewActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_name;
    private Button bt;
    private ImageView iv;
    private CheckBox cb;
    private RadioGroup rg;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_child_view);
        tv_name = (TextView)findViewById(R.id.tv_name);
        bt = (Button) findViewById(R.id.bt);
        iv = (ImageView) findViewById(R.id.iv);
        cb = (CheckBox) findViewById(R.id.cb);
        rg = (RadioGroup) findViewById(R.id.rg);

        tv_name.setOnClickListener(this);
        bt.setOnClickListener(this);
        iv.setOnClickListener(this);

        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Toast.makeText(ChildViewActivity.this, "Checkbox 是 " + isChecked, Toast.LENGTH_SHORT).show();
            }
        });

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb1:
                        Toast.makeText(ChildViewActivity.this, "RadioButton1 ", Toast.LENGTH_SHORT).show();
                        break;

                    case R.id.rb2:
                        Toast.makeText(ChildViewActivity.this, "RadioButton2 ", Toast.LENGTH_SHORT).show();
                        break;

                    case R.id.rb3:
                        Toast.makeText(ChildViewActivity.this, "RadioButton3 ", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
        rg.check(R.id.rb1);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_name:
                tv_name.setText("hello world");
                break;
            case R.id.bt:
                Toast.makeText(this, "button", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv:
                Toast.makeText(this, "IageView", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
